<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

<script type="text/javascript">
	var $dg_user ;
	$(function() {
		$dg_user = $("#dg_user").datagrid({
			url: base.contextPath+"/sysmgr/user/doNotNeedAuth_datagrid.do",
			fit: true, border: false, toolbar: '#dialogBar', pageSize: 30, pageList: [30,40,50,100,200],
			idField: 'id', striped:true, pagination: true, singleSelect: false,
			frozenColumns: [[
 			    { field: 'ck', checkbox: true },
 			    { field: 'id', title: 'ID', width: 80, hidden: true },
 			    { field: 'num', title: '编号', width: 80, sortable: true }
 			]],
 			columns: [[
			    { field: 'company_name', title: '公司', width: 150, sortable: true },
			    { field: 'dept_name', title: '部门', width: 100, sortable: true },
			    { field: 'truename', title: '姓名', width: 100, sortable: true },
			    { field: 'account', title: '登录账号', width: 100, sortable: true }, 
			    { field: 'status', title: '&nbsp;账号状态', width: 80, sortable: true, align: 'center', formatter:function(value,row){
			    	if(value == "0"){return "<font color='green'>允许登录</font>";}else{return "<font color='red'>禁止登录</font>";}
			    }},
			    { field: 'sex', title: '性别', width:50, sortable: true, align: 'center'},
			    { field: 'mobile', title: '手机号码', width:100, sortable: true },
			    { field: 'email', title: '邮箱地址', width: 200, sortable: true },
			    { field: 'group_name', title: '所属组', width: 180, sortable: true },
			    { field: 'lastAcceccTime', title: '最后访问', width: 180, sortable: true },
			    { field: 'diffDatetime', title: '闲置', width: 180, sortable: true },
			    { field: 'created', title: '创建时间', width: 140, sortable: true },
			    { field: 'modifyDate', title: '最后修改时间', width: 140, sortable: true }
			]],
			onLoadSuccess: function(row, data) {
	        	$.fn.datagrid.extensions.onLoadSuccess.apply(this, arguments);
	        	var user_ids = "${permit.user_ids}" ;
	        	if(user_ids.length > 0) {
		        $.each(user_ids.split(","), function(i, p) {
			    	$dg_user.datagrid("selectRecord", p) ;
		        	});
	        	}
	         }
		});
	});
	
	//验证表单
	var submitForm = function($d, $dg, flag) { 
		var ids = [];
		var rows = $dg_user.datagrid('getChecked');
		if (rows.length > 0) {
			for ( var i = 0; i < rows.length; i++) {
				ids.push(rows[i].id);
			}
		}
		var role_id = "${permit.id}" ;
		$.easyui.loading({ msg: "数据添加中，请稍等..."});
		$.post(base.contextPath+"/sysmgr/permits/doNotNeedAuth_addPermits_Users.do", {id: role_id, user_ids: ids.join(',')}, function(result) {
			if (result.status) {
				alertify.success(result.msg);$.easyui.loaded();
				if(flag==undefined||flag==false){$d.dialog("close") ;}
			} else {
				$.easyui.loaded();warning.success(result.msg);
			}
		}, 'json').error(function() { $.easyui.loaded(); });
	};
	function doSearch(value,name){
		var o = {} ;
		o[name] = value ;
		$dg_user.datagrid("load",o);
	}
	
</script>
<div id="dg_user">
	<div id="dialogBar">
		<a onclick="$dg_user.datagrid('reload');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_reload'">刷新</a>
		<a onClick="$dg_user.datagrid('unselectAll');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'icon-standard-application-xp'">取消选中</a>
		<input class="easyui-searchbox" data-options="prompt:'请输入关键字',menu:'#mm',searcher:doSearch" style="width:300px"></input>
		<div id="mm">
			<div data-options="name:'num', iconCls: 'icon-hamburg-zoom'">编号查询</div>
			<div data-options="name:'account', iconCls: 'icon-hamburg-zoom'">登录账号</div>
			<div data-options="name:'truename', iconCls: 'icon-hamburg-zoom'">真实姓名</div>
			<div data-options="name:'email', iconCls: 'icon-hamburg-zoom'">邮件地址</div>
			<div data-options="name:'sex', iconCls: 'icon-hamburg-zoom'">性别地址</div>
		</div>
		<a onClick="$dg_user.datagrid('load',{});" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_clear'">取消筛选</a>
	</div>
</div>
